﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;

namespace Portal.CMS
{
    public class ListNewsByGroupBLL
    {
        public ListNewsByGroupCls CreateModel(string ActiveLanguage, string ListNewsByGroupId)
        {
            return CreateModel(Environments.ConnectionString, ActiveLanguage, ListNewsByGroupId);
        }

        public ListNewsByGroupCls CreateModel(string ConnectionString,string ActiveLanguage,string ListNewsByGroupId)
        {
            string Query = "select * from TableListNewsByGroup where ListNewsByGroupId=@ListNewsByGroupId";
            SqlConnection sqlConnection = new SqlConnection(ConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            sqlCommand.Parameters.Add("@ListNewsByGroupId", SqlDbType.VarChar);
            sqlCommand.Parameters["@ListNewsByGroupId"].Value = ListNewsByGroupId;
            DataTable dtResult = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
            da.Fill(dtResult);
            if (dtResult.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                ListNewsByGroupCls ListNewsByGroupCls = new ListNewsByGroupCls();
                ListNewsByGroupCls.ListNewsByGroupId = (string)dtResult.Rows[0]["ListNewsByGroupId"];
                ListNewsByGroupCls.Subject = "";
                try
                {
                    ListNewsByGroupCls.Subject = (string)dtResult.Rows[0][ActiveLanguage + "Subject"];
                }
                catch { }
                ListNewsByGroupCls.belongSite = "";
                try
                {
                    ListNewsByGroupCls.belongSite = (string)dtResult.Rows[0]["belongSite"];
                }
                catch { }
                try
                {
                    ListNewsByGroupCls.Owner = (string)dtResult.Rows[0]["Owner"];
                }
                catch { }

                 try
                {
                    ListNewsByGroupCls.JumpGroupUrl = (string)dtResult.Rows[0]["JumpGroupUrl"];
                }
                catch { }

                return ListNewsByGroupCls;
            }
        }
        
        public ListNewsByGroupItemCls CreateModelItem(string ListNewsByGroupItemId)
        {
            return CreateModelItem(Environments.ConnectionString, ListNewsByGroupItemId);
        }

        public ListNewsByGroupItemCls CreateModelItem(string ConnectionString, string ListNewsByGroupItemId)
        {
            string Query = "select * from TableListNewsByGroupItem where ListNewsByGroupItemId=@ListNewsByGroupItemId";
            SqlConnection sqlConnection = new SqlConnection(ConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            sqlCommand.Parameters.Add("@ListNewsByGroupItemId", SqlDbType.VarChar);
            sqlCommand.Parameters["@ListNewsByGroupItemId"].Value = ListNewsByGroupItemId;
            DataTable dtResult = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
            da.Fill(dtResult);
            if (dtResult.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                ListNewsByGroupItemCls ListNewsByGroupItemCls = new ListNewsByGroupItemCls();
                ListNewsByGroupItemCls.ListNewsByGroupItemId = (string)dtResult.Rows[0]["ListNewsByGroupItemId"];
                ListNewsByGroupItemCls.ListNewsByGroupId = (string)dtResult.Rows[0]["fk_ListNewsByGroup_Id"];
                ListNewsByGroupItemCls.ListNewsByGroupItemName = (string)dtResult.Rows[0]["ListNewsByGroupItemName"];
                ListNewsByGroupItemCls.IndexOrder = (int)dtResult.Rows[0]["IndexOrder"];
                try
                {
                    ListNewsByGroupItemCls.ParentListNewsByGroupItemId = (string)dtResult.Rows[0]["fk_ParentListNewsByGroupItem_Id"];
                }
                catch { }
                return ListNewsByGroupItemCls;
            }
        }

        public DataTable ReadingForSyncFromTool(string ConnectionString, string belongSite)
        {
            string Query = "select ListNewsByGroupId from TableListNewsByGroup where belongSite='" + belongSite + "'";
            SqlConnection sqlConnection = new SqlConnection(Environment.Environments.ConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            DataTable dtResult = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
            da.Fill(dtResult);
            return dtResult;
        }


        public DataTable Reading(string belongSite)
        {
            string Query = "select * from TableListNewsByGroup where belongSite='" + belongSite+"'";
            SqlConnection sqlConnection = new SqlConnection(Environment.Environments.ConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            DataTable dtResult = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
            da.Fill(dtResult);
            return dtResult;
        }

        public DataTable ReadingListNewsByGroupItems(string ListNewsByGroupId)
        {
            string Query = "select * from TableListNewsByGroupItem where fk_ListNewsByGroup_Id=@ListNewsByGroupId order by [IndexOrder]";
            SqlConnection sqlConnection = new SqlConnection(Environment.Environments.ConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            sqlCommand.Parameters.Add("@ListNewsByGroupId", SqlDbType.VarChar);
            sqlCommand.Parameters["@ListNewsByGroupId"].Value = ListNewsByGroupId;
            DataTable dtResult = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
            da.Fill(dtResult);
            return dtResult;
        }

        public string AddListNewsByGroup(
            SqlTransaction sqlTransaction,
            string belongSite,
            string ActiveLanguage,
            string Subject,
            string JumpGroupUrl)
        {
            bool HasTrans = sqlTransaction != null;
            SqlConnection sqlConnection = null;
            if (HasTrans == false)
            {
                sqlConnection = new SqlConnection(Environment.Environments.ConnectionString);
                sqlConnection.Open();
                sqlTransaction = sqlConnection.BeginTransaction();
            }
            else
            {
                sqlConnection = sqlTransaction.Connection;
            }

            string ListNewsByGroupId = System.Guid.NewGuid().ToString();
            string Query = "Insert into TableListNewsByGroup(ListNewsByGroupId,belongSite,Subject,[" + ActiveLanguage + "Subject],JumpGroupUrl) values (@ListNewsByGroupId,@belongSite,@Subject,@Subject,@JumpGroupUrl)";
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Clear();
            sqlCommand.Parameters.Add("@ListNewsByGroupId", SqlDbType.VarChar);
            sqlCommand.Parameters["@ListNewsByGroupId"].Value=ListNewsByGroupId;

            sqlCommand.Parameters.Add("@Subject", SqlDbType.NVarChar);
            sqlCommand.Parameters["@Subject"].Value = Subject;

            sqlCommand.Parameters.Add("@belongSite", SqlDbType.NVarChar);
            sqlCommand.Parameters["@belongSite"].Value = belongSite;

            sqlCommand.Parameters.Add("@JumpGroupUrl", SqlDbType.NVarChar);
            sqlCommand.Parameters["@JumpGroupUrl"].Value = JumpGroupUrl;


            try
            {
                sqlCommand.ExecuteNonQuery();

                //if (Portal.Environment.Environments.UseFrontEndDatabase)
                //{
                //    DataSet ds = new DataSet("xml");
                //    ds.Tables.Add("ListNewsByGroup");
                //    ds.Tables[0].Columns.Add("belongSite");
                //    ds.Tables[0].Columns.Add("ListNewsByGroupId");
                //    ds.Tables[0].Columns.Add("ActiveLanguage");
                //    ds.Tables[0].Columns.Add("Subject");
                //    ds.Tables[0].Columns.Add("JumpGroupUrl");
                //    ds.Tables[0].Rows.Add(new object[]{
                //        belongSite,ListNewsByGroupId,ActiveLanguage,Subject,JumpGroupUrl
                //    });

                //    string XmlData = ds.GetXml();
                //    Environment.FrontEndWebService.asmx.Service[] WServices = FrontendWebServiceController.CreateWebService();
                //    for (int iIndexService = 0; iIndexService < WServices.Length; iIndexService++)
                //    {
                //        string RetValue = WServices[iIndexService].AddListNewsByGroup(Environments.SecurityCode, XmlData);
                //        if (RetValue.Trim().Length > 0)
                //        {
                //            throw new Exception("Webservice:" + RetValue);
                //        }
                //    }
                //}
                if (HasTrans == false)
                {
                    sqlTransaction.Commit();
                }
            }
            catch (Exception ex)
            {
                if (HasTrans == false)
                {
                    sqlTransaction.Rollback();
                }
                throw (ex);
            }
            return ListNewsByGroupId;
        }

        public string AddListNewsByGroupItem(
            SqlTransaction sqlTransaction, 
            string belongSite ,
            string ListNewsByGroupId,
            string Subject,
            string GroupNewsItemId,
            int IndexOrder,
            int MaxNews)
        {
            bool HasTrans = sqlTransaction != null;
            SqlConnection sqlConnection = null;
            if (HasTrans == false)
            {
                sqlConnection = new SqlConnection(Environment.Environments.ConnectionString);
                sqlConnection.Open();
                sqlTransaction = sqlConnection.BeginTransaction();
            }
            else
            {
                sqlConnection = sqlTransaction.Connection;
            }

            string ActiveLanguage=Environment.Environments.ActiveLanguage;
            string ListNewsByGroupItemId = System.Guid.NewGuid().ToString();
            string Query = "Insert into TableListNewsByGroupItem(ListNewsByGroupItemId,belongSite,Subject,[" + ActiveLanguage + "Subject],fk_ListNewsByGroup_Id,fk_GroupNewsItem_Id,MaxNews,IndexOrder) values (@ListNewsByGroupItemId,@belongSite,@Subject,@Subject,@fk_ListNewsByGroup_Id,@fk_GroupNewsItem_Id,@MaxNews,@IndexOrder)";
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Clear();
            sqlCommand.Parameters.Add("@ListNewsByGroupItemId", SqlDbType.VarChar);
            sqlCommand.Parameters["@ListNewsByGroupItemId"].Value = ListNewsByGroupItemId;

            sqlCommand.Parameters.Add("@belongSite", SqlDbType.NVarChar);
            sqlCommand.Parameters["@belongSite"].Value = belongSite;

            sqlCommand.Parameters.Add("@Subject", SqlDbType.NVarChar);
            sqlCommand.Parameters["@Subject"].Value = Subject;

            sqlCommand.Parameters.Add("@fk_ListNewsByGroup_Id", SqlDbType.VarChar);
            sqlCommand.Parameters["@fk_ListNewsByGroup_Id"].Value = ListNewsByGroupId;

            sqlCommand.Parameters.Add("@fk_GroupNewsItem_Id", SqlDbType.VarChar);
            sqlCommand.Parameters["@fk_GroupNewsItem_Id"].Value = GroupNewsItemId;


            sqlCommand.Parameters.Add("@IndexOrder", SqlDbType.Int);
            sqlCommand.Parameters["@IndexOrder"].Value = IndexOrder;

            sqlCommand.Parameters.Add("@MaxNews", SqlDbType.Int);
            sqlCommand.Parameters["@MaxNews"].Value = MaxNews;

       
            try
            {
                sqlCommand.ExecuteNonQuery();

                //if (Portal.Environment.Environments.UseFrontEndDatabase)
                //{
                //    DataSet ds = new DataSet("xml");
                //    ds.Tables.Add("ListNewsByGroup");
                //    ds.Tables[0].Columns.Add("belongSite");
                //    ds.Tables[0].Columns.Add("ActiveLanguage");
                //    ds.Tables[0].Columns.Add("ListNewsByGroupItemId");
                //    ds.Tables[0].Columns.Add("ListNewsByGroupId");
                //    ds.Tables[0].Columns.Add("Subject");
                //    ds.Tables[0].Columns.Add("GroupNewsItemId");
                //    ds.Tables[0].Columns.Add("IndexOrder");
                //    ds.Tables[0].Columns.Add("MaxNews");

                //    ds.Tables[0].Rows.Add(new object[]{
                //        belongSite,ActiveLanguage,ListNewsByGroupItemId,ListNewsByGroupId,Subject,GroupNewsItemId,IndexOrder,MaxNews
                //    });

                //    string XmlData = ds.GetXml();
                //    Environment.FrontEndWebService.asmx.Service[] WServices = FrontendWebServiceController.CreateWebService();
                //    for (int iIndexService = 0; iIndexService < WServices.Length; iIndexService++)
                //    {
                //        string RetValue = WServices[iIndexService].AddListNewsByGroupItem(Environments.SecurityCode, XmlData);
                //        if (RetValue.Trim().Length > 0)
                //        {
                //            throw new Exception("Webservice:" + RetValue);
                //        }
                //    }
                //}
                if (HasTrans == false)
                {
                    sqlTransaction.Commit();
                }
            }
            catch (Exception ex)
            {
                if (HasTrans == false)
                {
                    sqlTransaction.Rollback();
                }
                throw (ex);
            }
            return ListNewsByGroupItemId;
        }


        public void SaveListNewsByGroupItem(
            SqlTransaction sqlTransaction, 
            string ActiveLanguage,
            string ListNewsByGroupItemId, 
            string Subject, 
            int IndexOrder,
            int MaxNews)
        {
            bool HasTrans = sqlTransaction != null;
            SqlConnection sqlConnection = null;
            if (HasTrans == false)
            {
                sqlConnection = new SqlConnection(Environment.Environments.ConnectionString);
                sqlConnection.Open();
                sqlTransaction = sqlConnection.BeginTransaction();
            }
            else
            {
                sqlConnection = sqlTransaction.Connection;
            }

            string Query = " Update TableListNewsByGroupItem set ["+ActiveLanguage+"Subject]=@Subject,IndexOrder=@IndexOrder,MaxNews=@MaxNews where ListNewsByGroupItemId=@ListNewsByGroupItemId";
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Clear();
            sqlCommand.Parameters.Add("@ListNewsByGroupItemId", SqlDbType.VarChar);
            sqlCommand.Parameters["@ListNewsByGroupItemId"].Value = ListNewsByGroupItemId;

            sqlCommand.Parameters.Add("@Subject", SqlDbType.NVarChar);
            sqlCommand.Parameters["@Subject"].Value = Subject;

            sqlCommand.Parameters.Add("@IndexOrder", SqlDbType.Int);
            sqlCommand.Parameters["@IndexOrder"].Value = IndexOrder;

            sqlCommand.Parameters.Add("@MaxNews", SqlDbType.Int);
            sqlCommand.Parameters["@MaxNews"].Value = MaxNews;

         
            try
            {
                sqlCommand.ExecuteNonQuery();

                //if (Portal.Environment.Environments.UseFrontEndDatabase)
                //{
                //    DataSet ds = new DataSet("xml");
                //    ds.Tables.Add("ListNewsByGroup");
                //    ds.Tables[0].Columns.Add("ActiveLanguage");
                //    ds.Tables[0].Columns.Add("ListNewsByGroupItemId");
                //    ds.Tables[0].Columns.Add("Subject");
                //    ds.Tables[0].Columns.Add("IndexOrder");
                //    ds.Tables[0].Columns.Add("MaxNews");

                //    ds.Tables[0].Rows.Add(new object[]{
                //        ActiveLanguage,ListNewsByGroupItemId,Subject,IndexOrder,MaxNews
                //    });

                //    string XmlData = ds.GetXml();
                //    Environment.FrontEndWebService.asmx.Service[] WServices = FrontendWebServiceController.CreateWebService();
                //    for (int iIndexService = 0; iIndexService < WServices.Length; iIndexService++)
                //    {
                //        string RetValue = WServices[iIndexService].SaveListNewsByGroupItem(
                //            Environments.SecurityCode, XmlData);
                //        if (RetValue.Trim().Length > 0)
                //        {
                //            throw new Exception("Webservice:" + RetValue);
                //        }
                //    }
                //}
                if (HasTrans == false)
                {
                    sqlTransaction.Commit();
                }
            }
            catch (Exception ex)
            {
                if (HasTrans == false)
                {
                    sqlTransaction.Rollback();
                }
                throw (ex);
            }
        }



        public void UpdateListNewsByGroup(SqlTransaction sqlTransaction, string ActiveLanguage, string ListNewsByGroupId, string Subject, string JumpGroupUrl)
        {
            bool HasTrans = sqlTransaction != null;
            SqlConnection sqlConnection = null;
            if (HasTrans == false)
            {
                sqlConnection = new SqlConnection(Environment.Environments.ConnectionString);
                sqlConnection.Open();
                sqlTransaction = sqlConnection.BeginTransaction();
            }
            else
            {
                sqlConnection = sqlTransaction.Connection;
            }

            string Query = "Update TableListNewsByGroup set [" + ActiveLanguage + "Subject]=@Subject,JumpGroupUrl=@JumpGroupUrl where ListNewsByGroupId=@ListNewsByGroupId";
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Clear();
            sqlCommand.Parameters.Add("@ListNewsByGroupId", SqlDbType.VarChar);
            sqlCommand.Parameters["@ListNewsByGroupId"].Value = ListNewsByGroupId;

            sqlCommand.Parameters.Add("@Subject", SqlDbType.NVarChar);
            sqlCommand.Parameters["@Subject"].Value = Subject;

            sqlCommand.Parameters.Add("@JumpGroupUrl", SqlDbType.NVarChar);
            sqlCommand.Parameters["@JumpGroupUrl"].Value = JumpGroupUrl;


            try
            {
                sqlCommand.ExecuteNonQuery();

                //if (Portal.Environment.Environments.UseFrontEndDatabase)
                //{
                //    DataSet ds = new DataSet("xml");
                //    ds.Tables.Add("ListNewsByGroup");
                //    ds.Tables[0].Columns.Add("ActiveLanguage");
                //    ds.Tables[0].Columns.Add("ListNewsByGroupId");
                //    ds.Tables[0].Columns.Add("Subject");
                //    ds.Tables[0].Columns.Add("JumpGroupUrl");

                //    ds.Tables[0].Rows.Add(new object[]{
                //        ActiveLanguage,ListNewsByGroupId,Subject,JumpGroupUrl
                //    });

                //    string XmlData = ds.GetXml();
                //    Environment.FrontEndWebService.asmx.Service[] WServices = FrontendWebServiceController.CreateWebService();
                //    for (int iIndexService = 0; iIndexService < WServices.Length; iIndexService++)
                //    {
                //        string RetValue = WServices[iIndexService].UpdateListNewsByGroup(
                //            Environments.SecurityCode, XmlData);
                //        if (RetValue.Trim().Length > 0)
                //        {
                //            throw new Exception("Webservice:" + RetValue);
                //        }
                //    }
                //}
                if (HasTrans == false)
                {
                    sqlTransaction.Commit();
                }
            }
            catch (Exception ex)
            {
                if (HasTrans == false)
                {
                    sqlTransaction.Rollback();
                }
                throw (ex);
            }
        }



        public void DeleteListNewsByGroup(SqlTransaction sqlTransaction, string ListNewsByGroupId)
        {
            bool HasTrans = sqlTransaction != null;
            SqlConnection sqlConnection = null;
            if (HasTrans == false)
            {
                sqlConnection = new SqlConnection(Environment.Environments.ConnectionString);
                sqlConnection.Open();
                sqlTransaction = sqlConnection.BeginTransaction();
            }
            else
            {
                sqlConnection = sqlTransaction.Connection;
            }

            Environment.Permission.DeletePermission(sqlTransaction, ListNewsByGroupId);
            string Query =
                            " Delete from TableListNewsByGroupItem where fk_ListNewsByGroup_Id=@ListNewsByGroupId"+
                            " Delete from TableListNewsByGroup where ListNewsByGroupId=@ListNewsByGroupId";
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Clear();
            sqlCommand.Parameters.Add("@ListNewsByGroupId", SqlDbType.VarChar);
            sqlCommand.Parameters["@ListNewsByGroupId"].Value = ListNewsByGroupId;

            try
            {
                sqlCommand.ExecuteNonQuery();

                //if (Portal.Environment.Environments.UseFrontEndDatabase)
                //{
                //    DataSet ds = new DataSet("xml");
                //    ds.Tables.Add("ListNewsByGroup");
                //    ds.Tables[0].Columns.Add("ListNewsByGroupId");
                    
                //    ds.Tables[0].Rows.Add(new object[]{
                //        ListNewsByGroupId
                //    });

                //    string XmlData = ds.GetXml();
                //    Environment.FrontEndWebService.asmx.Service[] WServices = FrontendWebServiceController.CreateWebService();
                //    for (int iIndexService = 0; iIndexService < WServices.Length; iIndexService++)
                //    {
                //        string RetValue = WServices[iIndexService].DeleteListNewsByGroup(
                //            Environments.SecurityCode, XmlData);
                //        if (RetValue.Trim().Length > 0)
                //        {
                //            throw new Exception("Webservice:" + RetValue);
                //        }
                //    }
                //}
                if (HasTrans == false)
                {
                    sqlTransaction.Commit();
                }
            }
            catch (Exception ex)
            {
                if (HasTrans == false)
                {
                    sqlTransaction.Rollback();
                }
                throw (ex);
            }
        }


        public void DeleteListNewsByGroupItem(SqlTransaction sqlTransaction, string ListNewsByGroupItemId)
        {
            bool HasTrans = sqlTransaction != null;
            SqlConnection sqlConnection = null;
            if (HasTrans == false)
            {
                sqlConnection = new SqlConnection(Environment.Environments.ConnectionString);
                sqlConnection.Open();
                sqlTransaction = sqlConnection.BeginTransaction();
            }
            else
            {
                sqlConnection = sqlTransaction.Connection;
            }

            string Query =
                        " Delete from TableListNewsByGroupItem where ListNewsByGroupItemId=@ListNewsByGroupItemId";
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = Query;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Clear();
            sqlCommand.Parameters.Add("@ListNewsByGroupItemId", SqlDbType.VarChar);
            sqlCommand.Parameters["@ListNewsByGroupItemId"].Value = ListNewsByGroupItemId;

            try
            {
                sqlCommand.ExecuteNonQuery();

                //if (Portal.Environment.Environments.UseFrontEndDatabase)
                //{
                //    DataSet ds = new DataSet("xml");
                //    ds.Tables.Add("ListNewsByGroup");
                //    ds.Tables[0].Columns.Add("ListNewsByGroupItemId");

                //    ds.Tables[0].Rows.Add(new object[]{
                //        ListNewsByGroupItemId
                //    });

                //    string XmlData = ds.GetXml();
                //    Environment.FrontEndWebService.asmx.Service[] WServices = FrontendWebServiceController.CreateWebService();
                //    for (int iIndexService = 0; iIndexService < WServices.Length; iIndexService++)
                //    {
                //        string RetValue = WServices[iIndexService].DeleteListNewsByGroupItem(
                //            Environments.SecurityCode, XmlData);
                //        if (RetValue.Trim().Length > 0)
                //        {
                //            throw new Exception("Webservice:" + RetValue);
                //        }
                //    }
                //}
                if (HasTrans == false)
                {
                    sqlTransaction.Commit();
                }
            }
            catch (Exception ex)
            {
                if (HasTrans == false)
                {
                    sqlTransaction.Rollback();
                }
                throw (ex);
            }
        }


        public void PublishingPublicWebSite(string ListNewsByGroupId)
        {
            Environments.CheckFrontEndDatabase();
        }



        public void ItemPublishingPublicWebSite(string ListNewsByGroupItemId)
        {
            Environments.CheckFrontEndDatabase();
        }

        public void SyncWithServer(
             string ConnectionString,
             string ListNewsByGroupId,
             bool  UseWsForDeploy,
             string ActiveLanguage,
             string PathRoot,
             string WorkingPath,
             string PortalAlias,
             string WsUrl,
             string WsSecurityCode)
        {
            if (UseWsForDeploy)
            {
                ListNewsByGroupCls oListNewsByGroupCls = new ListNewsByGroupBLL().CreateModel(ActiveLanguage, ListNewsByGroupId);
                DataSet ds = new DataSet();
                string Query =
                    " select * from TableListNewsByGroup where ListNewsByGroupId=@ListNewsByGroupId;" +
                    " select * from TableListNewsByGroupItem where fk_ListNewsByGroup_Id=@ListNewsByGroupId";
                SqlConnection sqlConnectionCheck = new SqlConnection(ConnectionString);
                sqlConnectionCheck.Open();
                SqlCommand sqlCommandCheck = sqlConnectionCheck.CreateCommand();
                sqlCommandCheck.CommandText = Query;
                sqlCommandCheck.Parameters.Clear();
                sqlCommandCheck.Parameters.Add("@ListNewsByGroupId", SqlDbType.VarChar);
                sqlCommandCheck.Parameters["@ListNewsByGroupId"].Value = ListNewsByGroupId;

                SqlDataAdapter sqlda = new SqlDataAdapter(sqlCommandCheck);
                sqlda.Fill(ds);

                ds.Tables[0].TableName = "TableListNewsByGroup";
                ds.Tables[1].TableName = "TableListNewsByGroupItem";

                string XmlData = ds.GetXml();
                Framework.AppWs.WsReturnParamCls oWsReturnParamCls = Portal.Environment.Environments.CreateAppWs(WsUrl).SyncData(
                    WsSecurityCode,
                    ListNewsByGroupId,
                    oListNewsByGroupCls.belongSite,
                    XmlData,
                    null,
                    null,
                    null,
                    Framework.AppWs.ESycDataType.ListNewsByGroup);
                if (oWsReturnParamCls.Error) throw new Exception("WS: " + oWsReturnParamCls.ErrorMsg);
            }
        }


        public void SyncWithServer(
            string ListNewsByGroupId)
        {
            string WsUrl = Environments.GetConfigFromXml("AppWs");
            string WsSecurityCode = Portal.Environment.Environments.WsSecurityCode;
            bool UseWsForDeploy = Environments.UseWsForDeploy;
            SyncWithServer(
                Environment.Environments.ConnectionString,
                ListNewsByGroupId,
                UseWsForDeploy,
                Environments.ActiveLanguage,
                Environments.PathRoot,
                Environments.WorkingPath,
                Portal.Environment.Environments.PortalAlias,
                WsUrl,
                WsSecurityCode);
        }
    }
}
